package com.fieldchain.ex.fa100.utils.screen;

import android.content.Context;
import android.util.Log;

import com.fieldchain.ex.fa100.access.MyApplication;

public class Dputils {
    private static float scale = 1;

    public static int dp2px( float dpValue) {
        if(scale==1){
            scale = MyApplication.getAppContext().getResources().getDisplayMetrics().density;
        }
        Log.e("sss111",dpValue+"   "+(dpValue * scale + 0.5f));
        return (int) (dpValue * scale + 0.5f);
    }
    /**
     * px转换成dp
     */
    public static int px2dp(Context context, float pxValue) {
        if(scale==1){
            scale = MyApplication.getAppContext().getResources().getDisplayMetrics().density;
        }
        return (int) (pxValue / scale + 0.5f);
    }

}
